<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@page import="iwpl.project.entities.Areas"%>
<%@page import="iwpl.project.dao.*" %>
<%@page import="iwpl.project.entities.Contracts"%>
<%@page import="iwpl.project.entities.Customers"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@page import="iwpl.project.dao.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'Insert_BuyingContract.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
		<link rel="stylesheet" href="css/datepicker.css" type="text/css" />
		<script type="text/javascript" src="js/datepicker.js"></script>
<script src="js/jquery-Source.js"></script>
		<script type="text/javascript"
			src="js/jquery-Validation.js"></script>
		<script type="text/javascript">
  $(document).ready(function()
  {
    $("#commentForm").validate();
  });
  </script>
 
  </script>
  <script type="text/javascript">
  	function loadcontrol()
  	{
  		var bntsearchdate = document.getElementById("bntsearchdate");
  		var bntsearchname=document.getElementById("bntsearchname");
  		var txtdate = document.getElementById("txtdate");
  		var bntdate = document.getElementById("bntdate");
  		var txtfirstdate=document.getElementById("txtfirstdate");
  		var bntfirst=document.getElementById("bntfirst");
  		var txtfinaldate=document.getElementById("txtfinaldate");
  		var bntfinal=document.getElementById("bntfinal");
  		var bntsearchdatecus=document.getElementById("bntsearchdatecus");
  		txtfirstdate.disabled=true;
  		bntfirst.disabled=true;
  		txtfinaldate.disabled=true;
  		bntfinal.disabled=true;
  		bntsearchdatecus.disabled=true;
  		txtdate.disabled=true;
  		bntdate.disabled=true;
  		bntsearchdate.disabled=true;
  		bntsearchname.disabled=false;
  	}
  </script>
  <script type="text/javascript">
  	function search(control)
  	{
  		document.form1.action="/DepartmentManage/Result_Areas.jsp?control="+control;
  		document.form1.submit();
  	}
  </script>
  <script type="text/javascript">
  	function Controldata(control)
  	{
  		var bntsearchname=document.getElementById("bntsearchname");
  		var bntsearchdate = document.getElementById("bntsearchdate");
  		var txtdate = document.getElementById("txtdate");
  		var bntdate = document.getElementById("bntdate");
  		var txtfirstdate=document.getElementById("txtfirstdate");
  		var bntfirst=document.getElementById("bntfirst");
  		var txtfinaldate=document.getElementById("txtfinaldate");
  		var bntfinal=document.getElementById("bntfinal");
  		var bntsearchdatecus=document.getElementById("bntsearchdatecus");
  		var txtsearch=document.getElementById("txtsearch");
  		var cbosearch=document.getElementById("cbosearch");
  		if(control==1)
  		{
  			txtdate.disabled=true;
  			txtdate.value="";
  			bntdate.disabled=true;
  			bntsearchdate.disabled=true;
  			txtfirstdate.disabled=true;
  			txtfirstdate.value="";
  			bntfirst.disabled=true;
  			txtfinaldate.disabled=true;
  			txtfinaldate.value="";
  			bntfinal.disabled=true;
  			bntsearchname.disabled=false;
  			txtsearch.disabled=false;
  			cbosearch.disabled=false;
  			bntsearchdatecus.disabled=true;
  			
  		}
  		else if(control==2)
  		{
  			
  			bntsearchdatecus.disabled=true;
  			txtfirstdate.disabled=true;
  			txtfirstdate.value="";
  			bntfirst.disabled=true;
  			txtfinaldate.disabled=true;
  			txtfinaldate.value="";
  			bntfinal.disabled=true;
  			txtdate.disabled=false;
  			bntdate.disabled=false;
  			bntsearchdate.disabled=false;
  			txtsearch.disabled=true;
  			txtsearch.value="";
  			cbosearch.disabled=true;
  			bntsearchname.disabled=true;
  		}
  		else
  		{
  			bntsearchdatecus.disabled=false;
  			txtfirstdate.disabled=false;
  			bntfirst.disabled=false;
  			txtfinaldate.disabled=false;
  			bntfinal.disabled=false;
  			txtdate.disabled=true;
  			txtdate.value="";
  			bntdate.disabled=true;
  			bntsearchdate.disabled=true;
  			bntsearchname.disabled=true;
  			txtsearch.disabled=true;
  			txtsearch.value="";
  			cbosearch.disabled=true;
  		}
  	}
  </script>
  <script type="text/javascript">
  		function Insert()
  		{
  			document.form1.action="/DepartmentManage/ChooseContract.jsp?type=insert";
  			document.form1.submit();
  		}
  </script>
   <script type="text/javascript">
  		function update(id,type)
  		{
  			if(type==1)
  			{
  				document.form1.action="/DepartmentManage/Update_BuyingContract.jsp?action = updatebuying && id="+id;
  				document.form1.submit();
  			}
  			else
  			{
  				document.form1.action="/DepartmentManage/Update_HiringContract.jsp?action = updatehiring && id="+id;
  				document.form1.submit();
  			}
  		}
  </script>
  <script type="text/javascript">
  	function Confirm(id)
  	{
  		var text=confirm("Do you want to delete?")
  		if(text==true)
  		{
  			document.form1.action = "/DepartmentManage/servlet/Control_Contract?action=delete&id="+id;
  			document.form1.submit();
  			//location.href="/DepartmentManage/servlet/Control_Contract?delete="+id;
  		}
  	}
  </script>
  </head>
  
  <body onload="javascript:loadcontrol()">
     			<table align="center" border="1px" cellpadding="0" cellspacing="0"
				style="width: 780px; border-color: #3399FF">
				<tr>
					<td colspan="2"><jsp:include page="Header.jsp"></jsp:include>
					</td>
				</tr>
				<tr>
					<td style="width: 245px" nowrap="nowrap" valign="top">&nbsp;<jsp:include page="Left.jsp"></jsp:include>
					</td>
					<td style="width: 75%" valign="top">

			
   					 <hr width="100%"/>
    					<form id="form1" name="form1" action="/DepartmentManage/servlet/Control_Contract" method="post">
   						
   						<table border="1" bordercolor="red">
   							
   							
   							<tr bgcolor="blue">
   								<td><center><b>ID</b></center></td>
   								<td><center><b>ContractType</b></center></td>
   								<td><center><b>EmployeeName</b></center></td>
   								<td><center><b>CustomerName</b></center></td>
   								<td><center><b>SigningDate</b></center></td>
   								<td><center><b>HiringDate</b></center></td>
   								<td><center><b>EndDate</b></center></td>
   								<td><center><b>PurchaseDate</b></center></td>
   								<td><center><b>ReceivedofDate</b></center></td>
   								<td><center><b>Update</b></center></td>
   								<td><center><b>Delete</b></center></td>
   							</tr>
   							<%
   								ContractsDAO dao=new ContractsDAO();
   								Contracts ctr=new Contracts();
   								List data=dao.findAll();
   								Iterator ir=data.listIterator(); 
   								while(ir.hasNext())
   								{
   									String cusname="";
   									ctr=(Contracts)ir.next();
   									int ID=ctr.getId();
   									int ct=ctr.getContractType();
   									String empname=ctr.getEmployees().getFullName();
   									Collection <Customers> cus = ctr.getApartments().getCustomerses();
   										for(Iterator it=cus.iterator();it.hasNext();)
   										{
   											Customers cust=(Customers)it.next();
   											cusname+=cust.getFullName()+"</br>";
   											break;
   										}
   										Date Signingdate=ctr.getSigningDate();
   										Date HiringDate=ctr.getHiringDate();
   										Date EndDate=ctr.getEndDate();
   										Date Purdate=ctr.getPurchaseDate();
   										Date redate=ctr.getReceivedOfDate();
   										String contracttype="";
   										if(ct==1)
   											contracttype="Buy";
   										else
   											contracttype="Hire";
   										out.print("<tr>");
   										out.print("<td>");
   										out.print(ID);
   										out.print("</td>");
   										out.print("<td>");
   										out.print(contracttype);
   										out.print("</td>");
   										out.print("<td>");
   										out.print(empname);
   										out.print("</td>");
   										out.print("<td>");
   										out.print(cusname);
   										out.print("</td>");
   										out.print("<td>");
   										out.print(Signingdate);
   										out.print("</td>");
   										out.print("<td>");
   										out.print(HiringDate);
   										out.print("</td>");
   										out.print("<td>");
   										out.print(EndDate);
   										out.print("</td>");
   										out.print("<td>");
   										out.print(Purdate);
   										out.print("</td>");
   										out.print("<td>");
   										out.print(redate);
   										out.print("</td>");
   										out.print("<td>");
   										out.print("<center><a href=javascript:update("+ID+","+ct+")><img src=./images/Edit.jpg /></a></center>");
   										out.print("</td>");
   										out.print("<td>");
   										out.println("<center><a id=bnt_delete href =javascript:Confirm("+ID+")><img src=./images/Delete.jpg /></a></center>");
   										out.print("</td>");
   										out.print("</tr>");
   								}
   							 %>
   						</table>
						</form>
					</td>
				</tr>
			</table>
  </body>
</html>
